import { request } from '../../services/request';

// 扫码查询工单接口
export const scanBatchQrcodeApi = async (params: { qrcode: string }) => {
  console.log('请求接口: /app/work/scanBatchQrcode', params);
  const res = await request('/app/work/scanBatchQrcode', {
    method: 'POST',
    body: JSON.stringify(params),
  });
  console.log('扫码查询接口返回:', res);
  return res;
};

// 报工接口
export const apsWorkNewApi = async (params: {
  task_id?: string;
  work_quantity: string;
  fatal_quantity: string;
  wait_time: string;
  wait_time_type: string;
  work_order_num: string;
  mbom_num: string;
  process_name: string;
  work_device_id?: string; // 设备ID，当capacity为2时需要
  station_num?: string; // 工位号，当capacity为1时需要
  line_num?: string; // 产线号，当capacity为5时需要
  user_num?: string; // 用户号，当capacity为4时需要
}) => {
  console.log('请求接口: /app/work/apsWorkNew', params);
  const res = await request('/app/work/apsWorkNew', {
    method: 'POST',
    body: JSON.stringify(params),
  });
  console.log('报工接口返回:', res);
  return res;
};

// 开始接口
export const inStationApi = async (params: { task_id?: string }) => {
  console.log('请求接口: /app/work/inStation', params);
  const res = await request('/app/work/inStation', {
    method: 'POST',
    body: JSON.stringify(params),
  });
  console.log('开始接口返回:', res);
  return res;
};

// 结束接口
export const outStationApi = async (params: { task_id?: string }) => {
  console.log('请求接口: /app/work/outStation', params);
  const res = await request('/app/work/outStation', {
    method: 'POST',
    body: JSON.stringify(params),
  });
  console.log('结束接口返回:', res);
  return res;
};

// 退出登录接口
export const logoutApi = async () => {
  console.log('请求接口: /app/auth/logout');
  const res = await request('/app/auth/logout', {
    method: 'POST',
  });
  console.log('退出登录接口返回:', res);
  return res;
};
// 参数类型单选接口
export const getDomainDictByTypeEn = async (params: { type_en?: string }) => {
  console.log('请求接口: /app/sysDomainDict/getDomainDictByTypeEn', params);
  const res = await request('/app/sysDomainDict/getDomainDictByTypeEn', {
    method: 'POST',
    body: JSON.stringify(params),
  });
  console.log('参数类型单选接口返回:', res);
  return res;
};

// 获取设备列表接口
export const getProcessResourceListApi = async (params: { id: string }) => {
  console.log('请求接口: /app/work/getProcessResourceList', params);
  const res = await request('/app/work/getProcessResourceList', {
    method: 'POST',
    body: JSON.stringify(params),
  });
  console.log('获取设备列表接口返回:', res);
  return res;
};

// 扫码接口
export const scanApi = async (params: { qrcode: string }) => {
  console.log('请求接口: /app/work/scan', params);
  const res = await request('/app/work/scan', {
    method: 'POST',
    body: JSON.stringify(params),
  });
  console.log('绑定工位或产线接口返回:', res);
  return res;
};

// 根据产品编码获取工单接口（扫码专用）
export const getMBomByProductEncodeNewApi = async (params: {
  product_encode: string;
  sales_order_num: string;
}) => {
  console.log('请求接口: /app/work/getMBomByProductEncodeNew', params);
  const res = await request('/app/work/getMBomByProductEncodeNew', {
    method: 'POST',
    body: JSON.stringify(params),
  });
  console.log('根据产品编码获取工单接口返回:', res);
  return res;
};

// 根据工单和工序获取任务数据接口
export const getMesTaskByWorkOrderAndMbomNewApi = async (params: {
  work_order_id: string;
  mbom_num: string;
  mbom_id: string;
}) => {
  console.log('请求接口: /app/work/getMesTaskByWorkOrderAndMbomNew', params);
  const res = await request('/app/work/getMesTaskByWorkOrderAndMbomNew', {
    method: 'POST',
    body: JSON.stringify(params),
  });
  console.log('根据工单和工序获取任务数据返回:', res);
  return res;
};


